package com.gmlive.common.okhttpquality.internal;

import okhttp3.Response;

/**
 * 网络信息
 * @作者: 姜志敏
 * @日期: 2019-08-17
 */
public class IkOkHttpMonitor {
    public static final String NOT_PLAIN_TEXT = "Response is not plain text";
    public static final String NO_BODY = "Response has no body";

    /**
     * 网络错误类型
     */
    public enum Type {
        HTTP("http"),
        SOCKET("socket"),
        BUSINESS("business");

        private String type;

        Type(String type) {
            this.type = type;
        }

        public String value() {
            return type;
        }
    }

    private boolean isSuccessful = false;

    // status code
    private int code;

    // response message
    private String message;

    // host
    private String url;

    // api
    private String api;

    private long tookMs;

    private Type type;


    public IkOkHttpMonitor() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getApi() {
        return api;
    }

    public void setApi(String api) {
        this.api = api;
    }

    public long getTookMs() {
        return tookMs;
    }

    public void setTookMs(long tookMs) {
        this.tookMs = tookMs;
    }

    public String getType() {
        if(type != null){
            return type.value();
        }
        return "";
    }

    public void setType(Type type) {
        this.type = type;
    }

    public boolean isSuccessful() {
        return isSuccessful;
    }

    public void setSuccessful(boolean successful) {
        isSuccessful = successful;
    }

    @Override
    public String toString() {
        return "IkOkHttpMonitor{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", url='" + url + '\'' +
                ", api='" + api + '\'' +
                ", tookMs=" + tookMs + "ms" +
                ", type=" + type +
                '}';
    }
}
